package com.imut.onlinebanking.xrh.controller;

import com.imut.onlinebanking.base.response.StatusCode;
import com.imut.onlinebanking.base.response.JsonResult;
import com.imut.onlinebanking.user.pojo.entity.Lose;
import com.imut.onlinebanking.xrh.pojo.entity.Account;
import com.imut.onlinebanking.xrh.service.xrhSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

@Controller
@RequestMapping("/balance")
public class xrhController {
    @Autowired
    private xrhSer xrhSer;

    @GetMapping("/enquiry")
    @ResponseBody
    public JsonResult getAllLoses(@RequestParam String accountId) {
        try {
            List<Account> list = xrhSer.selectByAccountId(accountId);
            System.out.println("cs"+list);
            if (list != null && !list.isEmpty()) {
                return JsonResult.ok(list.get(0));
            } else {
                return new JsonResult(404, "账户不存在或无数据");
            }
        } catch (Exception e) {
            return new JsonResult(500, "服务器内部错误: " + e.getMessage());
        }
    }

    public List<Account> listAll(){
        return xrhSer.selectByAccount();
    }
}